﻿using System;
using System.Collections.Generic;

namespace SpellChecker
{
    internal class Leerzeichenverarbeiter
    {
        private static char[] WhiteSpaceCharacters = {'\t','\r','\n'};

        internal static string ReplaceAllWhiteSpaces(string Input)
        {
            string WhiteSpaceReducedInput = Input;

            foreach (var WhiteSpaceCharacter in WhiteSpaceCharacters)
            {
                WhiteSpaceReducedInput = WhiteSpaceReducedInput.Replace(WhiteSpaceCharacter, ' ');
            }

            return WhiteSpaceReducedInput;
        }

        public static IEnumerable<string> SplitIntoWords(string PuntuationMarkFreeText)
        {
            string WhiteSpaceReducedText = ReplaceAllWhiteSpaces(PuntuationMarkFreeText);
            string MultipleBlanksReduced = ReplaceMultipleBlanks(WhiteSpaceReducedText);

            return MultipleBlanksReduced.Trim().Split(' ');
        }

        internal static string ReplaceMultipleBlanks(string Input)
        {
            var MultipleBlanksRemoved = Input;

            while (MultipleBlanksRemoved.Contains("  "))
            {
                MultipleBlanksRemoved = MultipleBlanksRemoved.Replace("  ", " ");
            }

            return MultipleBlanksRemoved;
        }
    }
}